﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace ICarPool.ConfigManager
{
    public class WebConfig
    {
        /// <summary>
        /// 获取Webconfig中的数据库连接串
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static String GetConnectionByKey(String key)
        {
            try
            {
               return  ConfigurationManager.ConnectionStrings[key].ToString();
            }
            catch (Exception)
            {
                throw new Exception(String.Format(@"Web.config/ConnectionStrings下未配置:{0}节点.", key));
            }
        }

        /// <summary>
        /// 获取Webconfig中的AppSettings
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static String GetAppSettingByKey(String key)
        {
            try
            {
                return ConfigurationManager.AppSettings[key].ToString();
            }
            catch (Exception)
            {
                throw new Exception(String.Format(@"Web.config/AppSettings下配置:{0}节点.", key));
            }
        }
    }
}
